package me.baicai.weixin.identity.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.baicai.modules.belldandy.exception.service.GcbExceptionService;
import me.baicai.modules.belldandy.gcb.domain.FinancePayroll;
import me.baicai.weixin.application.Result;
import me.baicai.weixin.entity.gcb.Advertising;
import me.baicai.weixin.entity.gcb.Finance;
import me.baicai.weixin.entity.gcb.Query;
import me.baicai.weixin.entity.identity.Agent;
import me.baicai.weixin.entity.identity.Employee;
import me.baicai.weixin.entity.order.Account;
import me.baicai.weixin.identity.service.*;
import me.baicai.weixin.provider.service.WeixinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;


@Api(tags = "PC：PC操作")
@RestController
public class PCController
{

    @Autowired
    private ShopService shopService;

    @Autowired
    private AgentService agentService;

    @Autowired
    private LoginService loginService;

    @Autowired
    private PCService pcService;

    @Autowired
    private WeixinService weixinService;

    @Autowired
    private AdverTisingService adverTisingService;

    @Value("${gcb.system}")
    private String gm;

    @ApiOperation("系统注册用户查看")
    @PostMapping("/pc/identity")
    public Result identity(@Validated @RequestBody Query query)
    {
        return loginService.identity(query);
    }

    @ApiOperation("系统注册用户删除")
    @DeleteMapping("/pc/identity/{id}")
    public Result identity(@PathVariable Integer id)
    {
        return loginService.identity(id);
    }

    @ApiOperation("系统注册用户账户修改")
    @PostMapping("/pc/identityAccount")
    public Result identity(@Validated @RequestBody Account account)
    {
        return loginService.identity(account);
    }

    @ApiOperation("系统代理查看")
    @PostMapping("/pc/agent")
    public Result agent(@Validated @RequestBody Query query)
    {
        return agentService.agent(query);
    }

    @ApiOperation("获取所有二级代理")
    @GetMapping("/pc/agent")
    public Result agent()
    {
        return agentService.agent();
    }

    @ApiOperation("代理的店铺查看")
    @PostMapping("/pc/agentShop")
    public Result agentShop(@Validated @RequestBody Query query)
    {
        return agentService.agentShop(query);
    }

    @ApiOperation("系统代理信息修改添加")
    @PutMapping("/pc/agent")
    public Result agent(@Validated @RequestBody Agent agent)
    {
        return agentService.agent(agent);
    }

    @ApiOperation("订单列表")
    @PostMapping("/pc/order")
    public Result order(@Validated @RequestBody Query query)
    {
        return pcService.order(query);
    }

    @ApiOperation("结束并退款订单")
    @DeleteMapping("/pc/order/{id}")
    public Result order(@PathVariable String id)
    {
        return weixinService.refundOrder("", id);
    }

    @ApiOperation("订单下面的流水明细")
    @GetMapping("/pc/order/{id}")
    public Result orderInfo(@PathVariable String id)
    {
        return pcService.order(id);
    }

    @ApiOperation("设备列表")
    @PostMapping("/pc/device")
    public Result device(@Validated @RequestBody Query query)
    {
        return pcService.device(query);
    }

    @ApiOperation("设备删除")
    @DeleteMapping("/pc/device/{id}")
    public Result device(@PathVariable String id)
    {
        return agentService.deleteDevice(id);
    }

    @ApiOperation("商户列表")
    @PostMapping("/pc/shop")
    public Result shop(@Validated @RequestBody Query query)
    {
        return shopService.shop(query);
    }

    @ApiOperation("商户列表")
    @PostMapping("/pc/shopInfo")
    public Result shopInfo(@Validated @RequestBody Query query)
    {
        return shopService.shopInfo(query);
    }

    @ApiOperation("代理的打工仔")
    @GetMapping("/pc/employee/{id}")
    public Result employee(@PathVariable String id)
    {
        return agentService.employee(id);
    }

    @ApiOperation("微信提成审批")
    @PostMapping("/pc/withdrawalRecord")
    public Result withdrawalRecord(@Validated @RequestBody Query query)
    {
        return weixinService.withdrawalRecord(query);
    }

    @ApiOperation("微信提成审批")
    @PostMapping("/pc/withdrawalRecordOP")
    public Result withdrawalRecordOP(@Validated @RequestBody Query query)
    {
        return weixinService.approvalWithdrawal("", Integer.valueOf(query.getValue()),
            query.getType());
    }

    @ApiOperation("申请查看")
    @PostMapping("/pc/apply")
    public Result apply(@Validated @RequestBody Query query)
    {
        return pcService.apply(query);
    }

    @ApiOperation("申请处理")
    @PostMapping("/pc/processApply")
    public Result processApply(@Validated @RequestBody Query query)
    {
        return loginService.processApply(this.gm, query.getPage(), query.getSize(),
            query.getValue(), query.getType());
    }

    @ApiOperation("广告列表修改")
    @PutMapping("/pc/advertising")
    public Result advertising(@Validated @RequestBody Advertising Advertising)
    {
        return adverTisingService.advertising(Advertising);
    }

    @ApiOperation("广告列表")
    @PostMapping("/pc/advertising")
    public Result advertising(@Validated @RequestBody Query query)
    {
        return adverTisingService.advertising(query);
    }

    @ApiOperation("小程序首页信息")
    @GetMapping("/pc/information")
    public Result information()
    {
        return pcService.information();
    }

    @ApiOperation("故障记录")
    @PostMapping("/pc/faultRecord")
    public Result faultRecord(@Validated @RequestBody Query query)
    {
        return pcService.faultRecord(query);
    }

    @ApiOperation("财务数据")
    @GetMapping("/pc/financeData")
    public Result financeData(@RequestParam("yearIn") String yearIn,
                              @RequestParam("yearOut") String yearOut,
                              @RequestParam("monthIn") String monthIn,
                              @RequestParam("monthOut") String monthOut)
    {
        return pcService.financeData(yearIn, yearOut, monthIn, monthOut);
    }

    @ApiOperation("财务数据")
    @PutMapping("/pc/finance")
    public Result finance(@Validated @RequestBody Finance finance)
    {
        return pcService.finance(finance);
    }

    @ApiOperation("财务数据")
    @PostMapping("/pc/finance")
    public Result finance(@Validated @RequestBody Query query)
    {
        return pcService.finance(query);
    }

    @ApiOperation("上传工资条")
    @PostMapping("/pc/financeUpload")
    @ResponseBody
    public Result financeUpload(MultipartFile file)
        throws IOException
    {
        return pcService.financeUpload(file);
    }

    @ApiOperation("查询工资条")
    @GetMapping("/pc/financePayroll/{targe}")
    @ResponseBody
    public Result financePayroll(@PathVariable String targe)
    {
        return pcService.financePayroll(targe);
    }

    @ApiOperation("修改工资条")
    @PostMapping("/pc/financePayroll")
    @ResponseBody
    public Result financePayroll(@Validated @RequestBody FinancePayroll financePayroll)
        throws IOException
    {
        return pcService.financePayroll(financePayroll);
    }

    @ApiOperation("删除工资条")
    @DeleteMapping("/pc/financePayroll/{id}")
    @ResponseBody
    public Result financePayroll(@PathVariable Integer id)
        throws IOException
    {
        return pcService.financePayroll(id);
    }

    @ApiOperation("发送工资条")
    @GetMapping("/pc/sendFinancePayroll/{value}")
    @ResponseBody
    public Result sendFinancePayroll(@PathVariable String value)
        throws Exception
    {
        return pcService.sendFinancePayroll(value);
    }

    @ApiOperation("员工财务数据")
    @GetMapping("/pc/myFinance/{uid}")
    @ResponseBody
    public Result myFinance(@PathVariable Integer uid)
    {
        return pcService.myFinance(uid);
    }

    @ApiOperation("项目分成")
    @GetMapping("/pc/projectInfo")
    public Result projectInfo(@RequestParam("uid") Integer uid,
                              @RequestParam("pid") Integer pid,
                              @RequestParam("date") String date,
                              @RequestParam("type") String type)
    {
        return pcService.projectInfo(uid, pid, date, type);
    }
}
